﻿<?php
	//是否要退换货
	function getReturn($str)
	{
		if($str=='false')
			$getReturn = "否";
		else
			$getReturn = "是";
		return $getReturn;	
	}
	//判断退款状态
	function getStatus($str)
	{	
		if($str=='WAIT_SELLER_AGREE')
		   $getStatus = "买家已经申请退款，等待卖家同意";
		else if($str=='WAIT_BUYER_RETURN_GOODS')
		   $getStatus = "卖家已经同意退款，等待买家退货";
		else if($str=='WAIT_SELLER_CONFIRM_GOODS')
		   $getStatus = "买家已经退货，等待卖家确认收货";		   
		else if($str=='SELLER_REFUSE_BUYER')
		    $getStatus = "卖家拒绝退款";
		else if($str=='CLOSED')
		    $getStatus = "退款关闭";
		else
			$getStatus = "退款成功";
		return $getStatus;
	}

	//判断货物状态
	function getGood_Status($str)
	{	
		if($str=='BUYER_NOT_RECEIVED')
		   $getStatus = "买家未收到货";
		else if($str=='BUYER_RECEIVED')
		   $getStatus = "买家已收到货";
		else if($str=='BUYER_RETURNED_GOODS')
		   $getStatus = "买家已退货";		   
		else
			$getStatus = "未知状态";
		return $getStatus;
	}


	//判断交易状态
	function getOrder_Status($str)
	{	
		if($str=='WAIT_BUYER_PAY')
		   $getStatus = "等待买家付款";
		else if($str=='WAIT_SELLER_SEND_GOODS')
		   $getStatus = "买家已付款,等待卖家发货";
		else if($str=='WAIT_BUYER_CONFIRM_GOODS')
		   $getStatus = "卖家已发货,等待买家确认收货";		   
		else if($str=='TRADE_BUYER_SIGNED')
		    $getStatus = "买家已签收,货到付款专用";
		else if($str=='TRADE_FINISHED')
		    $getStatus = "交易成功";
		else if($str=='TRADE_CLOSED')
		    $getStatus = "交易关闭";						
		else
			$getStatus = "交易被淘宝关闭";
		return $getStatus;
	}
	
	//检测评价长度
	function clb($C_cahr, $I_len1, $I_len2=500){ 
		$C_cahr = trim($C_cahr); 
		if (mb_strlen($C_cahr)/3 < $I_len1) return false; 
		if (mb_strlen($C_cahr)/3 > $I_len2) return false; 
		return true; 
	} 
	
	//获取数据兼容file_get_contents与curl
	function vita_get_url_content($url) {
		if(function_exists('file_get_contents')) {
			$file_contents = file_get_contents($url);
		} else {
		$ch = curl_init();
		$timeout = 5; 
		curl_setopt ($ch, CURLOPT_URL, $url);
		curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
		curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
		$file_contents = curl_exec($ch);
		curl_close($ch);
		}
	return $file_contents;
	}
	
	//签名函数 
	function createSign ($paramArr) { 
	    global $appSecret; 
	    $sign = $appSecret; 
	    ksort($paramArr); 
	    foreach ($paramArr as $key => $val) { 
	       if ($key !='' && $val !='') { 
	           $sign .= $key.$val; 
	       } 
	    } 
	    $sign = strtoupper(md5($sign.$appSecret));
	    return $sign; 
	}

	//组参函数 
	function createStrParam ($paramArr) { 
	    $strParam = ''; 
	    foreach ($paramArr as $key => $val) { 
	       if ($key != '' && $val !='') { 
	           $strParam .= $key.'='.urlencode($val).'&'; 
	       } 
	    } 
	    return $strParam; 
	} 

	//解析xml函数
	function getXmlData ($strXml) {
		$pos = strpos($strXml, 'xml');
		if ($pos) {
			$xmlCode=simplexml_load_string($strXml,'SimpleXMLElement', LIBXML_NOCDATA);
			$arrayCode=get_object_vars_final($xmlCode);
			return $arrayCode ;
		} else {
			return '';
		}
	}
	
	function get_object_vars_final($obj){
		if(is_object($obj)){
			$obj=get_object_vars($obj);
		}
		if(is_array($obj)){
			foreach ($obj as $key=>$value){
				$obj[$key]=get_object_vars_final($value);
			}
		}
		return $obj;
	}
?>